package controllers

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/context"
)

type LoginController struct {
	CommonController
}

func (this *LoginController) Get() {
	this.TplName = "login.html"
}
func (this *LoginController) Post() {
	uname := this.Input().Get("uname")
	password := this.Input().Get("password")
	autoLogin := this.Input().Get("autoLogin") == "on"
	if beego.AppConfig.String("uname") == uname && beego.AppConfig.String("password") == password {
		maxAge := 0
		if autoLogin {
			maxAge = 100
		}
		this.Ctx.SetCookie("uname", uname, maxAge, "/")
		this.Ctx.SetCookie("password", password, maxAge, "/")
	}
	this.Redirect("/", 301)
	return
}

//func (this *LoginController) Po{st() {

//	username := this.Input().Get("username")
//	password := this.Input().Get("password")
//	if username != "luxiaofei" || password != "123456" {
//		this.TplName = "error.html"
//	} else {
//		maxAge := 1800
//		this.Ctx.SetCookie("username", this.Input().Get("username"), maxAge, '/')
//		this.Ctx.SetCookie("password", this.Input().Get("password"), maxAge, '/')
//		this.Redirect("/", 301)
//	}
//}

func checkAccount1(ctx *context.Context) bool {
	ck, err := ctx.Request.Cookie("username")
	if err != nil {
		return false
	}
	username := ck.Value
	ck, err = ctx.Request.Cookie("password")
	if err != nil {
		return false
	}
	password := ck.Value

	if username == "luxiaofei" && password == "123456" {
		return true
	} else {
		return false
	}

}
